/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.PriorityHeader;
import java.text.ParseException;

/**
 * The Priority header field indicates the urgency of the request as perceived
 * by the client.  The Priority header field describes the priority that the
 * SIP request should have to the receiving human or its agent. For example,
 * it may be factored into decisions about call routing and acceptance. For
 * these decisions, a message containing no Priority header field SHOULD be
 * treated as if it specified a Priority of <var>"Normal"</var>.
 * <p>
 * The Priority header field does not influence the use of communications
 * resources such as packet forwarding priority in routers or access to
 * circuits in PSTN gateways.
 * <p>
 * The currently defined priority values are:
 * <ul>
 * <li> EMERGENCY
 * <li> URGENT
 * <li> NORMAL
 * <li> NON_URGENT
 * </ul>
 * For Example:<br>
 * <code>Subject: Weekend plans<br>
 * Priority: non-urgent</code>
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class PriorityHeaderImpl extends HeaderBase implements PriorityHeader {
    private String priority;

    private static final PriorityHeaderParser parser = new PriorityHeaderParser();

    public PriorityHeaderImpl() {
        super(PriorityHeader.NAME);
    }

    PriorityHeaderImpl(byte[] data, int start, int end) {
        super(PriorityHeader.NAME, data, start, end);
    }

    public Object clone() {
        final PriorityHeaderImpl header = new PriorityHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.priority = this.priority;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return priority;
    }

    /**
     * Set priority of PriorityHeader
     *
     * @param priority the new string priority value.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the priority value.
     */

    public void setPriority(String priority) throws ParseException {
        parse();
        this.priority = priority;
        invalidateHeaderData();
    }

    /**
     * Gets the string priority value of the PriorityHeader.
     *
     * @return the string priority value of the PriorityHeader
     */

    public String getPriority() {
        parse();
        return this.priority;
    }
}
/*
 * $Log$
 */